#!/sw/bin/perl

use strict;
use warnings;

use Tk;
use Tk::Text;
use Tk::ROText;

my $font_size = 10;
my $font_family = 'Courier';

my $main_window = new MainWindow;



my $text = $main_window->Scrolled( "ROText",
                                   -width => 80,
                                   -height => 30,
                                   -wrap => 'word',
                                   -bg => 'white',
                                   -relief => 'sunken',
                                   -scrollbars => 'oe',
                                   -font => [
                                             -size => $font_size,
                                             -family => $font_family
                                             ]
                                 )->pack(-side   => 'top',
                                         -fill   => 'both',
                                         -expand => 1);


sub confiugre_text_field {
  my ( $text,
       $font_size,
       $font_family ) = @_;

  $text->tagConfigure('bold', -font => [ 
                                        -size => $font_size, 
                                        -family => $font_family, 
                                        -weight => 'bold' 
                                       ]);
  
  $text->tagConfigure('italic', -font => [ 
                                          -size => $font_size, 
                                          -family => $font_family, 
                                          -slant => 'italic'
                                         ]);
  
  $text->tagConfigure('uline', -underline => 'on');
  $text->tagConfigure('strike', -overstrike => 'on' );
}

sub push_formated_text {
  my ($text, $style, $message) = @_;
  my $init = $text->index( 'insert' );
  $text->insert( 'insert', $message );
  $text->tagAdd( $style, $init, 'insert' );
}

&push_formated_text( $text, 'bold', "YOUR MOM\n" );
&push_formated_text( $text, 'strike', "IS A WHORE\n" );


sub push_paragraph {
  my ($text, $input) = @_;
  $input =~ s/[\t\r\n]/ /g;
  $input =~ s/ +/ /g;
  $input = "\n\t$input\n";
  $text->insert( 'insert', $input );
}

sub push_line_break {
  my $text = shift;
  $text->insert( 'insert', "\n" );
}

sub push_unordered_list {
  my ($text, $list_ref) = @_;
  my $message = "";
  for my $obj ( @$list_ref ) {
    $message = "   -  $obj\n";
  }
  $text->insert( 'insert', $message );
}

sub push_ordered_list {
  my ( $text, $list_ref ) = @_;
  my $counter = 1;
  for ( @$list_ref ) {
    for ( 1 .. (3 + length( scalar( @$ref )) - length( $counter ))) {
      $message = $message . " ";
    }
    $message = $message .  "$counter.  $_\n";
    $counter++;
  }
  $text->insert( 'insert', $message );
}

push_paragraph( $text, "You mother and I had a lovery   sunday\r\t where she\n sucked
 my dick  =D");

MainLoop;


sub break;

my %xhtml_tags = 
  (
   #BODY TAGS
   '<document>'   => "",
   '</document>'  => "",

   '<head>'   => "",
   '</head>'  => "",
   '<body>'   => "",
   '</body>'  => "",

#   '<title>'  => "",
#   '</title>' => "",

   #BLOCK TAGS
   '<p>'           => "",
   '</p>'          => "",

   '<br />'        => "",

   '<div>'         => "",
   '</div>'        => "",

   '<li>'  => "",
   '</li>' => "",
   '<ol>'  => "", 
   '</ol>' => "", 
   '<ul>'  => "", 
   '</ul>' => "",

   #TEXT-FORMATTING
   '<code>'  => "",
   '</code>' => "",
   '<tt>'    => "",
   '</tt>'   => "",

   '<em>'  => "",
   '</em>' => "",
   '<site>'  => "",
   '</site>' => "",
   '<i>'  => "",
   '</i>' => "",

   '<strong>'  => "",
   '</strong>' => "",
   '<b>'  => "",
   '</b>' => "",

   '<colour>'  => "",
   '</colour>' => "",
   '<color>'  => "",
   '</color>' => ""
  );


#   '<blockquote>'  => "",
#   '</blockquote>' => "",
#   '<h1>'          => "",
#   '</h1>' => "",
#   '<h2>'  => "",
#   '</h2>' => "",
#   '<h3>'  => "",
#   '</h3>' => "",
#   '<h4>'  => "",
#   '</h4>' => "",
#   '<h5>'  => "",
#   '</h5>' => "",
#   '<h6>'  => "",
#   '</h6>' => "",

#   '<table>'       => "",
   #   '</table>'      => "",
   #   '<tr>'          => "",
   #   '</tr>' => "",
   #   '</td>'         => "",
   #   '<td>'          => "",
